﻿using Microsoft.AspNetCore.Http;
using Model.DTO.Manager;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Threading.Tasks;
using WPay.Infrastructure.Unity;

namespace WPay.Web.API
{
    public class Function
    {
        /// <summary>
        /// 获取redis登录信息
        /// </summary>
        /// <returns></returns>
        public static LoginUserDTO InitSession(HttpContext httpContext)
        {
            try
            {
                TokenModel tm = RayPIToken.GetTokenModel();
                var dto = Newtonsoft.Json.JsonConvert.DeserializeObject<LoginUserDTO>(tm.UserJson);
                if (dto == null)
                {
                    dto = new LoginUserDTO();
                    dto.DefActionList = new List<RoleAction_ModuleDTO>();
                    dto.UserActionList = new List<RoleActionDTO>();
                }
                return dto;

            }
            catch (Exception e)
            {
                return null;
                //throw new Exception("获取登录信息失败,请重新登录");
            }
        }
        public static bool IsLogin(HttpContext httpContext)
        {
            TokenModel tm = RayPIToken.GetTokenModel();
            return RayPIMemoryCache.Exists(tm.Uid);
        }
    }
}
